package com.naza.test.server;

import com.naza.rpc.Server.ClientBootstrap;
import com.naza.rpc.async.RpcCallback;
import com.naza.test.services.pojo.Person;
import com.naza.test.services.PersonManage;

/**
 * 非spring 模式下单种调用方式示例
 */
public class LocalClientSingleStarter {
    public static void main(String[] args) {
        ClientBootstrap b = new ClientBootstrap();
        b.setAddressAndProtocol("PROTOSTUFFSERIALIZE");
        ClientBootstrap.RpcInvoker rpc = b.getInvoker("com.naza.test.services.PersonManage");

        PersonManage personManage = (PersonManage)rpc.getObject();
        Person person = new Person();
        person.setAge(1);
        person.setName("test");
/*        int result = personManage.save(person);
        System.out.println("result:" + result);*/
        //1 proxy invoke
        for(int i =0 ;i<10;i++){
            Integer c = personManage.plus(1,2);
            System.out.println("------------------------"+c);
        }


        Class[] parameterTypes = new Class[2];
        parameterTypes[0] = int.class;
        parameterTypes[1] = int.class;

        Object[] params = new Object[2];
        params[0] = 1;
        params[1] = 2;

        //2 async invoke
/*        rpc.invokeAsync("plus",parameterTypes,params, new RpcCallback() {
            @Override
            public void onSuccess(Object result) {
                Integer r = (Integer) result;
                System.out.println("----------------------------"+r);
            }

            @Override
            public void onError(Exception error) {

            }
        });*/


/*        Integer d = (Integer) rpc.invokeSync("plus",parameterTypes,params);
        System.out.println(d);*/

/*        Class[] parameterTypes2 = new Class[1];
        parameterTypes2[0] = Person.class;

        Object[] params2 = new Object[1];
        params2[0] = person;

        //3 sync invoke
        Integer d = (Integer) rpc.invokeSync("save",parameterTypes2,params2);
        System.out.println(d);*/
    }
}
